package com.kifas.service.dataaccess;

import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.kifas.entity.ReferenceNumberingEntity;

@Repository
public class ReferenceNumberingDao {
	@SuppressWarnings("unused")
	private static Logger log = Logger.getLogger(ReferenceNumberingDao.class);

	@Autowired
	private SessionFactory sessionFactory;

	public String getNextReference(Integer unit, String prefix) {
		return (String) sessionFactory.getCurrentSession().createSQLQuery("{? = call getNumbering(:unit,:prefix)}").setInteger("unit", unit)
				.setString("prefix", prefix).uniqueResult();
	}

	public void insert(ReferenceNumberingEntity referenceNumbering) throws Exception {
		sessionFactory.getCurrentSession().save(referenceNumbering);
	}

}
